<template>
	<view>
		 
			<clxDialog :isShow='cancelAccountShow' @dialogConfirm='dialogConfirm' @dialogCancel='dialogCancel'
				 :title="title"></clxDialog>
			 <clxDialogFail :isShow='failShow' @dialogConfirm='dialogConfirm1' @dialogCancel='dialogConfirm1'
			 	:content="dialogContent1" :title="title1"></clxDialogFail>
				
				<clxDialogSuccess :isShow='successShow' @dialogConfirm='dialogConfirm2'  
					:content="dialogContent2" :title="title2" :isShowCancel="false" confirmText="退出APP"></clxDialogSuccess>
			
			<view class="cancelAccountInfoView">
				<view class="cancelAccount-text1"  style="margin-bottom: 20px;">为了确保你的账号、车辆、权限安全，派方将在你注销账号前进行以下验证</view>
				<view class="line"></view>
				<view class="cancelAccount-text1"  style="margin-top: 20px;margin-bottom: 10px;"> ·无进行中的订单</view>
				<view class="cancelAccount-text2">该账号下的所有订单均已完成（包括但不限于车辆订单、预约试驾订单等）</view>
				<view class="cancelAccount-text1"  style="margin-top: 20px;margin-bottom: 10px;"> ·账号下无任何关联车辆</view>
				<view class="cancelAccount-text2">该账号下无任何车辆，且不是任何一辆车的主用车人、共同用车人或授权用车人</view>
				<view class="cancelAccount-text1"  style="margin-top: 20px;margin-bottom: 10px;"> ·阅读并同意《重要提醒》</view>
				<view class="cancelAccount-text2">阅读并同意《重要提醒》中的所有内容，并确保注销账号为本人操作</view>
			</view>
			
			
			
			<view class="info-pey">
				<view class="jurisdiction">
					<view>
						<checkbox-group @change="onCheckChange">
							<checkbox value="vvv" :checked="checked" style="transform: scale(0.64);"></checkbox>
						</checkbox-group>
					</view>
					<view class="checkbox-test">
						我已阅读并同意
					</view>
					<view class="checkbox-test" @click="importantReminder" style="color: #EA5404;">
						《重要提醒》
					</view>
			
				</view>
				<view class="unOperationBtn"   v-if="checked==false">申请注销账号</view>
				<view class="operationBtn" v-else @click="cancelAccount">申请注销账号</view>
				
			</view>
			
			
	  
		 
	</view>
</template>

<script>
	const app = getApp();
	import clxDialog from "@/components/clx-dialog/clx-dialog";
	import clxDialogFail from "@/components/clx-dialog/clx-dialog";
	import clxDialogSuccess from "@/components/clx-dialog/clx-dialog";
	
	const network = require("../../../manager/network-manager.js");
	const util = require("@utils/util.js");
	
	
	export default {
		data() {
			return {
				checked:false,
				title: '是否确认注销本账号？',
				cancelAccountShow: false,
				
				failShow:false,
				title1: '注销失败',
				dialogContent1:'检测到有未完成的订单/未解绑的车辆信息，无法注销',
				
				successShow:false,
				title2:'注销申请成功',
				dialogContent2:'您的账号已申请注销，请留意系统短信通知',
				
				
				userInfo: null,
			}
		}, 
		components: {
			clxDialog,
			clxDialogFail,
			clxDialogSuccess
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) { 
			
		},
		onShow: function() { 
			if (app.globalData.userInfo) {
				this.userInfo = app.globalData.userInfo
			} else {
				this.userInfo = null
			}
			
			
		},
		props: {},
		methods: {
			//重要提醒
			importantReminder: function(e) {
				uni.navigateTo({
					url: '/module_my/pages/setting/importantReminder'
				})
			},
			
			//勾选购车协议
			onCheckChange: function(e) {
				this.checked = e.detail.value.length > 0;
				 
			},
			//点击申请注销账号
			cancelAccount:function(){
				this.cancelAccountShow = true
			},
			//取消申请注销账号
			dialogCancel() {
				this.cancelAccountShow = false
			},
			//确定申请注销账号
			dialogConfirm() {
				this.cancelAccountShow = false
				this.logout()
			},
			//注销方法
			logout(){
				var that = this;
				var uri = app.globalData.config.interfaces.URL_SYS_LOGOUT;
				var params = {
					"loginId": app.getUserId()
				};
						
				network.post(uri, params, 'form').then(res => {
					
					if (res.code == 200) {
						app.saveUser(null);
						app.saveToken(null);
						this.successShow = true
					} else {
						this.failShow=true
					}
				}).catch(res => {
					console.error(res, 'err')
				});
			},
			 
			//确定申请失败
			dialogConfirm1() {
				this.failShow = false
			},
			//确定申请成功
			dialogConfirm2(){
				this.successShow = false
				// #ifdef APP-PLUS
				if (plus.os.name.toLowerCase() === 'android') {
					 plus.runtime.quit();
				} else { 
					 const threadClass = plus.ios.importClass("NSThread");
					 const mainThread = plus.ios.invoke(threadClass, "mainThread");
					 plus.ios.invoke(mainThread, "exit");
					 // 或者如下
					 // plus.ios.import('UIApplication').sharedApplication().performSelector('exit');
				 }
				// #endif
			}
			
			 
		}
	}
</script>

<style>
	@import "./setting.css";
	
</style>
